﻿using System.Configuration;
using System.IO;
using System.Reflection;
using System.Web.UI.WebControls;
using CH.FourBoards.LagerWalti.FrontEnd.View;
using CH.FourBoards.LagerWalti.FrontEnd.View.Util;
using CH.FourBoards.LagerWalti.WebFrontEnd.View.Warehouse;

namespace CH.FourBoards.LagerWalti.WebFrontEnd.View.Master
{
    public class Main : System.Web.UI.MasterPage
    {

        public void ShowError(string error)
        {
            MainContent.Visible = false;
            ErrorMessage = error;
            ErrorPanel.Visible = true;
        }

        #region Controls

        protected Panel ErrorPanel;
        protected Panel InternalMenuPanel;
        protected ContentPlaceHolder MainContent;

        #endregion

        #region Page Properties

        protected string ErrorMessage { get; private set; }

        protected string HomeLink
        {
            get { return Root + new Home().CreateLink(); }
        }

        protected string WebShopLink
        {
            get { return "http://store.freebordswitzerland.com/en/"; }
        }

        protected string WarehouseLink
        {
            get { return Root + new InventoryView().CreateLink(); }
        }

        protected string CategoryListLink
        {
            get { return Root + new CategoryList().CreateLink(); }
        }

        protected string ProductListLink
        {
            get { return Root + new ProductList().CreateLink(); }
        }

        protected string PageStyle
        {
            get
            {
                var ret = "";
#if test
				ret += "background-color: #9acd32;";
#endif
                return ret;
            }
        }

        protected string ProfileName
        {
            get
            {
                return ConfigurationManager.AppSettings["ProfileName"];
            }
        }

        protected string SprintName
        {
            get
            {
                return ConfigurationManager.AppSettings["VersionName"];
            }
        }

        protected string ReleaseDate
        {
            get
            {
                var date = new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
                return new ContentRenderer().ToDateOnly(date);
            }
        }

        #endregion

        protected string Root
        {
            get
            {
                var ret = Context.Request.ApplicationPath;
                ret = ret ?? string.Empty;
                if (!ret.EndsWith("/")) {
                    ret += "/";
                }
                return ret;
            }
        }


    }
}